home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / OpenDoc / CreditNow! / CreditNow! Source / $Sources / CPCreditNowDemo.Image.cpp < prev    next >
Encoding:
Text File  |  1995-05-01  |  13.0 KB  |  446 lines  |  [TEXT/MPCC]

  1. //----------------------------------------------------------------------------------------
  2. // Imaging protocol
  3. //----------------------------------------------------------------------------------------
  4.  
  5. #ifndef _CREDITNOWDEMO_
  6. #include "CPCreditNowDemo.h"
  7. #endif
  8.  
  9. #ifndef __ICONS__
  10. #include <Icons.h>
  11. #endif
  12.  
  13. #ifndef SOM_ODDispatcher_xh
  14. #include <Disptch.xh>
  15. #endif
  16.  
  17. #if GENERATING68K
  18. #pragma segment Imaging
  19. #endif
  20.  
  21. //----------------------------------------------------------------------------------------
  22.  
  23. void CPCreditNowDemo::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
  24. {
  25.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_Draw
  26.     EnteringMethod("\pCPCreditNowDemo::Draw");
  27.     ODUnused(invalidShape);
  28.  
  29.     CFocus    foc(ev, facet);
  30.  
  31.     ODTypeToken view = facet->GetFrame(ev)->GetViewType(ev);
  32.  
  33.     if (view == fSession->Tokenize(ev, kODViewAsLargeIcon))
  34.     {
  35.         this->PrivDrawAsLargeIcon(ev, facet, invalidShape);
  36.         return;
  37.     }
  38.     
  39.     if (view == fSession->Tokenize(ev, kODViewAsSmallIcon))
  40.     {
  41.         this->PrivDrawAsSmallIcon(ev, facet, invalidShape);
  42.         return;
  43.     }
  44.     
  45.     if (view == fSession->Tokenize(ev, kODViewAsThumbnail))
  46.     {
  47.         this->PrivDrawAsThumbnail(ev, facet, invalidShape);
  48.         return;
  49.     }
  50.     
  51.     if (view == fSession->Tokenize(ev, kODViewAsFrame))
  52.     {
  53.         ODFrame*    frame     = facet->GetFrame(ev);
  54.         ODShape*    usedShape = frame->GetUsedShape(ev, kODNULL);
  55.         RgnHandle    rgn       = usedShape->GetQDRegion(ev);
  56.     
  57.         usedShape->Release(ev);
  58.     
  59.         Rect        rct     = (*rgn)->rgnBBox;
  60.         RgnHandle    oldClip = NULL;
  61.     
  62.         if (frame->IsRoot(ev))
  63.         {
  64.             GrafPtr    curPort;
  65.     
  66.             ::GetPort(&curPort);
  67.             ::EraseRect(&(curPort->portRect));
  68.         }
  69.         else {
  70.             ::EraseRoundRect(&rct, 40, 40);
  71.             ::PenSize(3, 3);
  72.             ::FrameRoundRect(&rct, 40, 40);
  73.             ::PenNormal();
  74.         }
  75.     
  76.     //AET<<
  77.         // Draw all the text boxes, button, and our fancy PICTs
  78.         
  79.         for ( TextFieldLink *fl = fTextFields.First(); fl->GetTextField(); fl = fl->Next() )
  80.             ( ((LabeledTextField*)fl->GetTextField()) )->Draw(rgn);
  81.     
  82.         fAddressVerify->Draw(rgn);
  83.         fAuthorization->Draw(rgn);
  84.         
  85.         this->ShowNiceImages( ev, facet );        // rgacsun
  86.  
  87.         //Draw Button
  88.         //assume the window origin is where it was when control was created (0,0)
  89.         if (frame->IsRoot(ev))
  90.             ::SetOrigin(0,0);
  91.         ::PenSize(3, 3);
  92.         Rect r = (**fAuthButton).contrlRect;
  93.         ::InsetRect(&r, -4, -4);
  94.         ::FrameRoundRect(&r,16, 16);
  95.         ::PenNormal();
  96.         ::Draw1Control(fAuthButton);
  97.     //AET>>
  98.     
  99.         if (oldClip) {
  100.             ::SetClip(oldClip);
  101.             ::DisposeRgn(oldClip);
  102.         }
  103.     }
  104. }
  105.  
  106. //----------------------------------------------------------------------------------------
  107.  
  108. static pascal OSErr PrivDetachIconResource(ResType theType, Handle *theIcon, void* yourDataPtr)
  109. {
  110.     if (theIcon != kODNULL && *theIcon != kODNULL)
  111.     {
  112.         ::DetachResource(*theIcon);
  113.         return ::ResError();
  114.     }
  115.     else
  116.         return noErr;
  117. }
  118.  
  119. //----------------------------------------------------------------------------------------
  120.  
  121. void CPCreditNowDemo::PrivDrawAsLargeIcon(Environment* ev, ODFacet* facet, ODShape* invalidShape)
  122. {
  123.     Rect                rect32;
  124.     IconTransformType     transformType = ttNone;
  125.     Handle                iconSuite;
  126.     
  127.     // Check to see if the icon is selected and in an active window
  128.     if ( facet->GetHighlight(ev) == kODFullHighlight && facet->GetWindow(ev)->IsActive(ev) )
  129.         transformType = ttSelected;
  130.     
  131.     // Draw the icon.
  132.     {
  133.         CUsingLibraryResources res;
  134.         OSErr error = ::GetIconSuite(&iconSuite, kHelloIconSuite, svAllLargeData);        
  135.     
  136.         if ( error == noErr )
  137.         {
  138.             // Create a universal proc pointer for our icon action proc.
  139.             IconActionUPP actionProc = NewIconActionProc(PrivDetachIconResource);
  140.             error = ::ForEachIconDo(iconSuite, svAllLargeData, actionProc, kODNULL);
  141.             DisposeRoutineDescriptor(actionProc);
  142.         }
  143.     }
  144.     
  145.     ::SetRect(&rect32, 0, 0, kODLargeIconSize, kODLargeIconSize);
  146.     ::PlotIconSuite(&rect32, atAbsoluteCenter, transformType, iconSuite);
  147.  
  148.     if ( facet->GetHighlight(ev) == kODDimHighlight )
  149.     {
  150.         ODShape* usedShape = facet->GetFrame(ev)->GetUsedShape(ev, kODNULL);
  151.         RgnHandle usedRgn = usedShape->GetQDRegion(ev);
  152.         
  153.         ::PenPat(&ODQDGlobals.gray);
  154.         ::FrameRgn(usedRgn);
  155.         ::PenNormal();
  156.         
  157.         usedShape->Release(ev);
  158.     }
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162.  
  163. void CPCreditNowDemo::PrivDrawAsSmallIcon(Environment* ev, ODFacet* facet, ODShape* invalidShape)
  164. {
  165.     Rect                rect16;
  166.     IconTransformType     transformType = ttNone;
  167.     Handle                iconSuite;
  168.     
  169.     // Check to see if the icon is selected and in an active window
  170.     if ( facet->GetHighlight(ev) == kODFullHighlight && facet->GetWindow(ev)->IsActive(ev) )
  171.         transformType = ttSelected;
  172.     
  173.     // Draw the icon.
  174.     {
  175.         CUsingLibraryResources res;
  176.         OSErr error = ::GetIconSuite(&iconSuite, kHelloIconSuite, svAllSmallData);        
  177.     
  178.         if ( error == noErr )
  179.         {
  180.             // Create a universal proc pointer for our icon action proc.
  181.             IconActionUPP actionProc = NewIconActionProc(PrivDetachIconResource);
  182.             error = ::ForEachIconDo(iconSuite, svAllLargeData, actionProc, kODNULL);
  183.             DisposeRoutineDescriptor(actionProc);
  184.         }
  185.     }
  186.     
  187.     ::SetRect(&rect16, 0, 0, kODSmallIconSize, kODSmallIconSize);
  188.     ::PlotIconSuite(&rect16, atAbsoluteCenter, transformType, iconSuite);
  189.  
  190.     if ( facet->GetHighlight(ev) == kODDimHighlight )
  191.     {
  192.         ODShape* usedShape = facet->GetFrame(ev)->GetUsedShape(ev, kODNULL);
  193.         RgnHandle usedRgn = usedShape->GetQDRegion(ev);
  194.         
  195.         ::PenPat(&ODQDGlobals.gray);
  196.         ::FrameRgn(usedRgn);
  197.         ::PenNormal();
  198.         
  199.         usedShape->Release(ev);
  200.     }
  201. }
  202.  
  203. //----------------------------------------------------------------------------------------
  204.  
  205. void CPCreditNowDemo::PrivDrawAsThumbnail(Environment* ev, ODFacet* facet, ODShape* invalidShape)
  206. {
  207.     // The last image displayed as frame is used as a Thumbnail
  208.     Rect rct;
  209.     ::SetRect(&rct, 0, 0, kODThumbnailSize, kODThumbnailSize);
  210.     if (fThumbnailPicture)
  211.         ::DrawPicture(fThumbnailPicture, &rct);
  212. }
  213. //----------------------------------------------------------------------------------------
  214.  
  215. void CPCreditNowDemo::CanvasUpdated(Environment* ev, ODCanvas* canvas)
  216. {
  217.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_CanvasUpdated
  218.     EnteringMethod("\pCPCreditNowDemo::CanvasUpdated");
  219.     ODUnused(canvas);
  220. }
  221.  
  222. //----------------------------------------------------------------------------------------
  223.  
  224. void CPCreditNowDemo::HighlightChanged(Environment* ev, ODFacet* facet)
  225. {
  226.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_HighlightChanged
  227.     EnteringMethod("\pCPCreditNowDemo::HighlightChanged");
  228.     ODUnused(facet);
  229. }
  230.  
  231. //----------------------------------------------------------------------------------------
  232.  
  233. ODULong CPCreditNowDemo::GetPrintResolution(Environment* ev, ODFrame* frame)
  234. {
  235.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_GetPrintResolution
  236.     EnteringMethod("\pCPCreditNowDemo::GetPrintResolution");
  237.     ODUnused(frame);
  238.     return 0;
  239. }
  240.  
  241. //----------------------------------------------------------------------------------------
  242.  
  243. void CPCreditNowDemo::FacetAdded(Environment* ev, ODFacet* facet)
  244. {
  245.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_FacetAdded
  246.     EnteringMethod("\pCPCreditNowDemo::FacetAdded");
  247.  
  248.     ODFrame* frame = facet->GetFrame(ev);
  249.     frame->RequestFrameShape(ev, this->PrivGetFrameShape(ev, frame), kODNULL);
  250.         // First, PrivGetFrameShape is called to calculate the frame
  251.         // shape we want.  However, we might not get it, due to the
  252.         // needs/constraints of the containing part.  Therefore, after
  253.         // calculating what we want, we see if we can get it by calling
  254.         // RequestFrameShape.
  255.         // RequestFrameShape either returns us what we passed it, or
  256.         // returns something else because it thinks it knows best.
  257.         // Either way, we then proceed with the returned result.
  258.         // Note that this means that we have to be prepared to deal
  259.         // with a frame shape other than we desire.
  260.  
  261.     this->PrivAdjustFacets(ev, frame);
  262.         // Given a new negotiated frame shape, adjust our facets based
  263.         // on it.  That's all there is to it.
  264.  
  265.     if (frame->IsRoot(ev))
  266.     {
  267.         ODBoolean succeeded = kODFalse;
  268.         succeeded = fSession->GetArbitrator(ev)->RequestFocusSet(ev, fFocusSet,frame);
  269.         if (succeeded)
  270.         {
  271.             this->FocusAcquired(ev, fSelectionFocus, frame);
  272.             this->FocusAcquired(ev, fMenuFocus, frame);
  273.             this->FocusAcquired(ev, fKeyFocus, frame);
  274.         }
  275.     }
  276. //AET<<
  277.     {
  278.         fFacet = facet;
  279.         CFocus    foc(ev, facet);
  280.         this->CreateTextFields(ev);
  281.  
  282.         this->CreateButton(ev, facet);
  283.  
  284.         //tell it the part, a frame(optional), idle frequency
  285.         ( fSession->GetDispatcher(ev) )->RegisterIdle(ev, fSelf, kODNULL, 1);
  286.         (fCurrentField->GetTextField())->Activate();
  287.  
  288.     }
  289. //AET>>
  290. }
  291.  
  292. //----------------------------------------------------------------------------------------
  293.  
  294. void CPCreditNowDemo::FacetRemoved(Environment* ev, ODFacet* facet)
  295. {
  296.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_FacetRemoved
  297.     EnteringMethod("\pCPCreditNowDemo::FacetRemoved");
  298. }
  299.  
  300. //----------------------------------------------------------------------------------------
  301.  
  302. void CPCreditNowDemo::CanvasChanged(Environment* ev, ODFacet* facet)
  303. {
  304.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_CanvasChanged
  305.     EnteringMethod("\pCPCreditNowDemo::CanvasChanged");
  306.     ODUnused(facet);
  307. }
  308.  
  309. //----------------------------------------------------------------------------------------
  310.  
  311. void CPCreditNowDemo::GeometryChanged(Environment* ev, ODFacet* facet,
  312.                                                    ODBoolean clipShapeChanged,
  313.                                                    ODBoolean externalTransformChanged)
  314. {
  315.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_GeometryChanged
  316.     EnteringMethod("\pCPCreditNowDemo::GeometryChanged");
  317.     ODUnused(facet);
  318.     ODUnused(clipShapeChanged);
  319.     ODUnused(externalTransformChanged);
  320. }
  321.  
  322.  
  323.  
  324.  
  325. //AET<<
  326. //----------------------------------------------------------------------------------------
  327. // CPCreditNowDemo::CreateTextFields
  328. //----------------------------------------------------------------------------------------
  329.  
  330. void CPCreditNowDemo::CreateTextFields(Environment* ev)
  331. {
  332.     ODTypeToken        aToken;
  333.     Rect            aRect;
  334.     
  335.     // Text Output Fields
  336.     
  337.     aToken     = fSession->Tokenize(ev, kAuthorizationTextField);
  338.     SetRect(&aRect,10,170,310,190);            // rgacsat
  339.     fAuthorization = new LabeledTextField();
  340.     fAuthorization->InitTextField(aToken, 60, 100, &aRect, "\pAuthorization ");
  341.  
  342.     aToken     = fSession->Tokenize(ev, kAddressVerificationTextField);
  343.     SetRect(&aRect,10,146,310,166);            // rgacsat
  344.     fAddressVerify = new LabeledTextField();
  345.     fAddressVerify->InitTextField(aToken, 60, 100, &aRect, "\pResult ");
  346.     
  347.     // Input fields
  348.     // fields must be created in reverse order that you want them in the list
  349.     // last field created is first field in list.
  350.     aToken     = fSession->Tokenize(ev, kAmountTextField);                // 6
  351.     SetRect(&aRect,175,112,310,132);
  352.     fTextFields.Add(aToken, 20, 70, &aRect, "\pAmount $:");
  353.  
  354.     aToken     = fSession->Tokenize(ev, kExpirationTextField);            // 5
  355.     SetRect(&aRect,10,112,160,132);
  356.     fTextFields.Add(aToken, 5, 100, &aRect, "\pExpiration:");
  357.  
  358.     aToken     = fSession->Tokenize(ev, kCreditNumberTextField);        // 4
  359.     SetRect(&aRect,10,88,310,108);
  360.     fTextFields.Add(aToken, 19, 100, &aRect, "\pCredit Card:");
  361.  
  362.     aToken     = fSession->Tokenize(ev, kCSZTextField);                    // 3
  363.     SetRect(&aRect,10,64,310,84);
  364.     fTextFields.Add(aToken, 100, 100, &aRect, "\pCity, State Zip:");
  365.  
  366.     aToken     = fSession->Tokenize(ev, kAddressTextField);                // 2
  367.     SetRect(&aRect,10,40,310,60);
  368.     fTextFields.Add(aToken, 100, 100, &aRect, "\pAddress:");
  369.  
  370.     aToken     = fSession->Tokenize(ev, kNameTextField);                // 1
  371.     SetRect(&aRect,10,16,310,36);
  372.     fTextFields.Add(aToken, 60, 100, &aRect, "\pName:");
  373.  
  374.     fCurrentField = fTextFields.First();
  375.  
  376.     // see CreateButton for Button creation
  377. }
  378. //AET>>
  379.  
  380.  
  381. //AET<<
  382. //----------------------------------------------------------------------------------------
  383. // CPCreditNowDemo::CreateButton
  384. //----------------------------------------------------------------------------------------
  385.  
  386. void CPCreditNowDemo::CreateButton(Environment* ev, ODFacet *facet)
  387. {
  388.     ODWindow* window = facet->GetWindow(ev);
  389.     ODFrame*    frame     = facet->GetFrame(ev);
  390.     if (kODNULL == fAuthButton)
  391.     {
  392.         WindowPtr wnd = window->GetPlatformWindow(ev);
  393.         Rect r;
  394.         if (frame->IsRoot(ev))
  395.             ::SetOrigin(0,0);
  396.         ::SetRect(&r, 220, 217, 302, 237);
  397.         fAuthButton = ::NewControl(wnd, &r, "\pAuthorize", true, 0, 0, 0, pushButProc, 0);
  398.     }
  399.     if (frame->IsRoot(ev))
  400.         ::SetOrigin(0,0);
  401.     ::ShowControl(fAuthButton);
  402. }
  403. //AET>>
  404.  
  405. //RGACSUN>>
  406. void CPCreditNowDemo::ShowNiceImages( Environment* ev, ODFacet *facet )
  407. {
  408.     Rect        aRect;
  409.     PicHandle    hPic    = nil;
  410.     
  411.     ODWindow*    window    = facet->GetWindow(ev);
  412.     ODFrame*    frame    = facet->GetFrame(ev);
  413.     
  414.     if (frame->IsRoot(ev))
  415.         ::SetOrigin(0,0);
  416.         
  417.     // Draw thick/think line in middle of screen.
  418.     ::PenSize(2, 2);
  419.     ::MoveTo( 5, 138 );
  420.     ::LineTo( 308, 138 );    // heavy upper line
  421.     ::PenNormal();
  422.     ::MoveTo( 5, 141 );
  423.     ::LineTo( 309, 141 );    // light lower line
  424.     
  425.     // Draw an outline around the image area.    
  426.                     // 0, 0,   209,  48
  427.     ::SetRect( &aRect, 7, 200, 216, 248);    // left, top, right, bottom
  428.  
  429.     // Get the image to display
  430.     {
  431.         CUsingLibraryResources fil;
  432.         hPic = (PicHandle)GetResource( 'PICT', 1128 );
  433.         if( nil != hPic )
  434.             ::DetachResource((Handle)hPic);        // Must detach it!
  435.     }
  436.  
  437.     if( nil != hPic )
  438.     {
  439.         HLock( (Handle)hPic );
  440.         DrawPicture( hPic, &aRect );    // same rectangle as the outline above.
  441.         HUnlock( (Handle)hPic );
  442.     }
  443. }
  444. //RGACSUN>>
  445.  
  446.